package org.dxy.middleware.dynamic.thread.pool.trigger.sdk.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dxy.middleware.dynamic.thread.pool.application.command.commandhandler.RefreshThreadPoolConfigCommandHandler;
import org.dxy.middleware.dynamic.thread.pool.application.query.repository.AThreadPoolQueryRepository;
import org.dxy.middleware.dynamic.thread.pool.application.view.ThreadPoolView;
import org.dxy.middleware.dynamic.thread.pool.domain.command.RefreshThreadPoolConfigCommand;
import org.dxy.middleware.dynamic.thread.pool.trigger.sdk.ThreadPoolConfigSDK;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ description:
 * @ author: dxy
 * @ createTime: 2025/10/2 13:54
 */

@Slf4j
@Component
@RequiredArgsConstructor
public class ThreadPoolConfigSDKImpl implements ThreadPoolConfigSDK {
    private final RefreshThreadPoolConfigCommandHandler handler;
    private final AThreadPoolQueryRepository threadPoolQueryRepository;


    @Override
    public void refresh(RefreshThreadPoolConfigCommand command) {
        log.info("SDK 调用刷新线程池配置: {}", command);
        handler.handle(command);
    }

    @Override
    public List<ThreadPoolView> getThreadPoolViewList() {
        return threadPoolQueryRepository.findAll();
    }

    @Override
    public ThreadPoolView getThreadPoolView(String appName, String threadPoolName) {
        return threadPoolQueryRepository.findByAppNameAndPoolName(appName, threadPoolName);
    }
}
